/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rockpaperscissors;

import java.util.Scanner;

/**
 *
 * @author Anne
 */
public class RockPaperScissors {

    private static boolean checkForWinner(String p1, String p2) {
        boolean playerOneWins = false;

        if (p1.equals("R") && p2.equals("S")
                || p1.equals("S") && p2.equals("P")
                || p1.equals("P") && p2.equals("R")) {
            playerOneWins = true;
        }
        return playerOneWins;
    }

    private static boolean checkPlayerOneWins(String p1, String p2) {
        return checkForWinner(p1, p2);
    }

    private static boolean checkPlayerTwoWins(String p1, String p2) {
        return checkForWinner(p2, p1);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String p1, p2;
        Scanner keyboard = new Scanner(System.in);
        boolean noWinner = true;
        boolean playAgain = true;

        while (noWinner == true || playAgain == true) {

            // p1 && p2 will be one of '(r p s)
            System.out.println("Player 1");
            System.out.println("Please enter your choice for the Rock-Paper-Scissors Game:");
            System.out.println("R: rock");
            System.out.println("P: paper");
            System.out.println("S: scissors");
            System.out.println("Paper covers rock, Rock breaks scissors, Scissors cut paper!!");

            p1 = keyboard.next();
            p1 = p1.toUpperCase();

            System.out.println("Player 2");
            System.out.println("Please enter your choice for the Rock-Paper-Scissors Game:");
            System.out.println("R: rock");
            System.out.println("P: paper");
            System.out.println("S: scissors");
            System.out.println("Paper covers rock, Rock breaks scissors, Scissors cut paper!!");

            p2 = keyboard.next();
            p2 = p2.toUpperCase();

            noWinner = true;
            //Method call to check if player 1 wins. 
            if (checkPlayerOneWins(p1, p2) == true) {
                noWinner = false;
                System.out.println("*** Player 1 WINS! ***");
            }
            //Method call to check if player 2 wins
            if (noWinner == true) {
                if (checkPlayerTwoWins(p1, p2) == true) {
                    noWinner = false;
                    System.out.println("*** Player 2 WINS! ***");
                }
            }

            //No Winner to the game - automatic replay testing commit
            if (noWinner == false) {

                System.out.println("Would you like to play again?))");
                System.out.println("Please enter your choice for the Rock-Paper-Scissors Game:");
                System.out.println("y: Yes");
                System.out.println("N: No");

                String answer = keyboard.next();
                answer = answer.toUpperCase();

                if (answer.equals("Y")) {
                    playAgain = true;
                } else {
                    playAgain = false;
                }
            } else {
                System.out.println("*** ->> TIE, automatically playing again <<- ***");
            }

        }

    }
}
